import request from '../../../utils/request'
import {
  User,
  UserResponseData,
  AssginRolesParams,
  ResponseGetAllRoles,
} from './type'

enum API {
  ALLUSER_URL = '/admin/acl/user/',
  ADDUSER_URL = '/admin/acl/user/save',
  UPDUSER_URL = '/admin/acl/user/update',
  DELETE_URL = '/admin/acl/user/remove/',
  BATCHDELETE_URL = '/admin/acl/user/batchRemove',
  ASSGINROLES_URL = '/admin/acl/user/doAssignRole',
  GETALLROLES_URL = '/admin/acl/user/toAssign/',
}

export const reqAllUser = (page: number, limit: number) =>
  request.get<UserResponseData>(API.ALLUSER_URL + `${page}/${limit}`)

export const reqAddOrUpdUser = (data: User) => {
  if (data.id) {
    return request.put<any>(API.UPDUSER_URL, data)
  } else {
    return request.post<any>(API.ADDUSER_URL, data)
  }
}

export const reqDeleteUser = (id: number) =>
  request.delete<any>(API.DELETE_URL + id)

export const reqBatchDeleteUser = (idArr: number[]) =>
  // request.delete(API.DELETEALLUSER_URL, { data: idList })  如何看出来参数需要这样写
  request.delete<any>(API.BATCHDELETE_URL, { data: idArr })

export const reqRolesList = (id: number) =>
  request.get<any>(API.GETALLROLES_URL + id)

export const reqAssginRoles = (roleParams: AssginRolesParams) =>
  request.post<ResponseGetAllRoles>(API.ASSGINROLES_URL, roleParams)

export const reqAssginAllRoles = (roleParams: AssginRolesParams) =>
  request.post<ResponseGetAllRoles>(API.ASSGINROLES_URL, { data: roleParams })
